---@class UIFuncOpenView : UIBase
UIFuncOpenView = UIBase.New(PanelResNames.UIFuncOpenView)
local t = UIFuncOpenView

function t.Init(id,content,obj)
    t.id = id
    t.content = content
    t.clickObj = obj
    UIBase.Init(t)
end

function t:OnCreate()
    self.title = self:GetChild("title")
    self.levelLockText = self:GetChild("levellocktext")
    self.des = self:GetChild("text1")
    self.team = self:GetChild("n12")
end
function t:Refresh()
    local cfg = dataTable.getDataTableByStringId("t_functionswitch",t.id)
    if not cfg then
        logError("找不到t_functionswitch："..tostring(t.id))
        return
    end
    self.title.text = getLanguage(cfg.f_FunctionName)
    self.levelLockText.text = t.content
    self.des.text = getLanguage(cfg.f_FunctionOpenDes)
end
function t:OnEnable()
    self:RegisterEvent(Config.EventType.TouchAnyKey,self.ClickClose)
    self:RegisterEvent(Config.EventType.Fight_Finish,self.ClickClose)

    self:Refresh()
    if t.clickObj then
        local zero = {};
        zero.x = 0;
        zero.y = 0;
        --local screenPos = t.clickObj:LocalToGlobal(Vector2.zero);
        local screenPos = t.clickObj.parent:TransformPoint(t.clickObj.xy, self.team.parent);
        local x = math.max(screenPos.x + t.clickObj.width * 0.5 - self.team.width * 0.5, 0);
        local y = math.max(screenPos.y - self.team.height - 10, 0);
        if self.team.width + x > GRoot.inst.width-Config.uiXOffset*2 then
            x = GRoot.inst.width - self.team.width;
            self.team.x = x - Config.uiXOffset*2
        else
            self.team.x = x
        end
        self.team.y = y
    else
        self.team.x = GRoot.inst.width / 2 - self.team.width / 2
        self.team.y = GRoot.inst.height / 2 - self.team.height / 2
    end
    
    
end
function t:OnDisable()
    self:UnRegisterEvent(Config.EventType.TouchAnyKey, self.ClickClose)
    self:UnRegisterEvent(Config.EventType.Fight_Finish,self.ClickClose)
end

function t:OnDestroy()
end
function t:ClickClose()
    closeUI(PanelNames.UIFuncOpenView)
end
return t